You can use the NewPtr function to allocate a nonrelocatable block of memory. If you want to allocate new blocks of memory with their bits precleared to 0, you can use the NewPtrClear function.
You should not call any of these memory-allocation routines at interrupt time.<36pt>
You can use the DisposePtr procedure to free nonrelocatable blocks of memory you have allocated.
You can use the NewPtr function to allocate a nonrelocatable block of memory of a specified size.
FUNCTION NewPtr (logicalSize: Size): Ptr;
The NewPtr function attempts to allocate, in the current heap zone, a nonrelocatable block with a logical size of logicalSize bytes and then return a pointer to the block. If the requested number of bytes cannot be allocated, NewPtr returns NIL .
The NewPtr function attempts to reserve space as low in the heap zone as possible for the new block. If it is able to reserve the requested amount of space, NewPtr allocates the nonrelocatable block in the gap ReserveMem creates. Otherwise, NewPtr returns NIL and generates a memFullErr error.
The registers on entry and exit for NewPtr are
Registers on exit |
|
---|---|
If you want to clear the bytes of a block of memory to 0 when you allocate it with the NewPtr function, set bit 9 of the routine trap word. You can usually do this by supplying the word CLEAR as the second argument to the routine macro, as follows:
_NewPtr ,CLEAR
You can use the NewPtrClear function to allocate prezeroed memory in a nonrelocatable block of a specified size.
FUNCTION NewPtrClear (logicalSize: Size): Ptr;
The NewPtrClear function works much as the NewPtr function does, but sets all bytes in the new block to 0 instead of leaving the contents of the block undefined.
Currently, NewPtrClear clears the block one byte at a time. For a large block, it might be faster to clear the block manually a long word at a time.
When you are completely done with a nonrelocatable block, call the DisposePtr procedure to free it for other uses.
PROCEDURE DisposePtr (p: Ptr);
The DisposePtr procedure releases the memory occupied by the nonrelocatable block specified by p .
After a call to DisposePtr , all pointers to the released block become invalid and should not be used again. Any subsequent use of a pointer to the released block might cause a system error.